package com.myhome.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.myhome.entity.MenuRole;
import com.myhome.entity.RespBean;
import com.myhome.mapper.MenuRoleMapper;
import com.myhome.service.IMenuRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2021-09-04
 */
@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements IMenuRoleService {

    @Autowired
    MenuRoleMapper menuRoleMapper;
    @Override
    public RespBean updateMenus(Integer rid,Integer[] mids) {
        Integer updateCount = menuRoleMapper.delete(new QueryWrapper<MenuRole>().eq("rid", rid));
        if (mids.length == 0 || null == mids) {
            return RespBean.success("修改成功");
        }
        Integer count = menuRoleMapper.insertMenus(rid, mids);
        if (count == mids.length) {
            return RespBean.success("修改成功");
        }
        return RespBean.error("修改失败");
    }
}
